package com.crazyxmq.rabbitmq;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.DeliverCallback;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeoutException;

public class Recv {

    public static void main(String[] args) throws Exception {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("127.0.0.1");

            Connection connection = factory.newConnection();
            Channel channel = connection.createChannel();

            channel.queueDeclare("hello",false,false,false,null);

            System.out.println("开始等待消费消息");
            DeliverCallback deliverCallback = (consumerTag,deliver) ->{
              String message = new String(deliver.getBody(),"UTF-8");
                System.out.println(message);
            };

            channel.basicConsume("hello",true,deliverCallback,consumerTag->{});


    }
}
